﻿using Cdx.Ui.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Cdx.Ui.Commands
{
    public class CommandCreateDocument: CommandBase
    {
        private Guid m_UserId;
        HttpPostedFileBase m_File;

        public CommandCreateDocument(Model model, Guid userId, HttpPostedFileBase file): base(model)
        {
            m_File = file;
            m_UserId = userId;
        }

        public override void Execute()
        {
            byte[] buffer = new BinaryReader(m_File.InputStream).ReadBytes((int)m_File.InputStream.Length);
            
            base.Model.Engine.CreateDocument(m_UserId, new FileInfo(m_File.FileName).Name, buffer); 
        }
    }
}